add_library(common-marcos-interface INTERFACE)
target_compile_definitions(common-marcos-interface
        INTERFACE
        G_LOG_DOMAIN="vvxfconf-common"
)

configure_file(
        ${CMAKE_CURRENT_SOURCE_DIR}/xfconf-dbus.xml.in
        ${CMAKE_CURRENT_BINARY_DIR}/xfconf-dbus.xml
        @ONLY
)

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xfconf-marshal.h
    COMMAND	glib-genmarshal
                --prefix=_xfconf_marshal --header
                ${CMAKE_CURRENT_SOURCE_DIR}/xfconf-marshal.list
                --output ${CMAKE_CURRENT_BINARY_DIR}/xfconf-marshal.h
)

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xfconf-marshal.c
    COMMAND	glib-genmarshal
                --prefix=_xfconf_marshal --body
                ${CMAKE_CURRENT_SOURCE_DIR}/xfconf-marshal.list
                --output ${CMAKE_CURRENT_BINARY_DIR}/xfconf-marshal.c
)

set(common_SOURCES
        xfconf-errors.c
        xfconf-types.c
        ${CMAKE_CURRENT_BINARY_DIR}/xfconf-marshal.c
        ${CMAKE_CURRENT_BINARY_DIR}/xfconf-marshal.h
        xfconf-alias.h
        xfconf-aliasdef.c
)

add_library(common
        STATIC
        ${common_SOURCES}
)

set(common_deps)
if (${IS_ALONE_COMPILE})
        list(APPEND common_deps PkgConfig::GLIB)
        list(APPEND common_deps PkgConfig::GIO)
else()
        list(APPEND common_deps glib-shared)
endif()

target_link_libraries(common
        PUBLIC
        marcos-interface
        common-marcos-interface
        ${common_deps}
)

#libxfconf_built_sources = \
#	xfconf-alias.h \
#	xfconf-aliasdef.c
#

set(gvaluefuncs_SOURCES
        xfconf-gvaluefuncs.c
        xfconf-gvaluefuncs.h
)
add_library(gvaluefuncs
        STATIC
        ${gvaluefuncs_SOURCES}
)

set(gvaluefuncs_deps)
if (${IS_ALONE_COMPILE})
        list(APPEND gvaluefuncs_deps PkgConfig::GLIB)
        list(APPEND gvaluefuncs_deps PkgConfig::GIO_UNIX)
else()
        list(APPEND gvaluefuncs_deps glib-shared)
endif()
target_link_libraries(gvaluefuncs
        PUBLIC
        marcos-interface
        common-marcos-interface
        common
        ${gvaluefuncs_deps}
)


#xfconf-gdbus-bindings.h:
#xfconf-gdbus-bindings.c: xfconf-dbus.xml Makefile
#	$(AM_V_GEN) $(GDBUS_CODEGEN) \
#	--interface-prefix @XFCONF_SERVICE_NAME_PREFIX@.Xfconf \
#	--annotate "@XFCONF_SERVICE_NAME_PREFIX@.Xfconf" "org.gtk.GDBus.C.Name" Exported \
#	--c-namespace Xfconf   \
#	--generate-c-code xfconf-gdbus-bindings \
#	$<

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xfconf-gdbus-bindings.c
    COMMAND	gdbus-codegen
                --interface-prefix @XFCONF_SERVICE_NAME_PREFIX@.Xfconf
                --annotate "${XFCONF_SERVICE_NAME_PREFIX}.Xfconf" "org.gtk.GDBus.C.Name" Exported
                --c-namespace Xfconf
                --generate-c-code xfconf-gdbus-bindings
                ${CMAKE_CURRENT_BINARY_DIR}/xfconf-dbus.xml
)

set(dbus_SOURCES
        ${CMAKE_CURRENT_BINARY_DIR}/xfconf-gdbus-bindings.c
        # xfconf-gdbus-bindings.h
)

add_library(dbus
        STATIC
        ${dbus_SOURCES}
)
set(dbus_deps)
if (${IS_ALONE_COMPILE})
        list(APPEND dbus_deps PkgConfig::GIO_UNIX)
else()
        list(APPEND dbus_deps glib-shared)
endif()
target_link_libraries(dbus
        PUBLIC
        ${dbus_deps}
)


#BUILT_SOURCES = \
#	xfconf-marshal.c \
#	xfconf-marshal.h \
#	xfconf-gdbus-bindings.c \
#	xfconf-gdbus-bindings.h
#
#xfconf-dbus.xml: xfconf-dbus.xml.in
#	$(SED) -e "s,\@XFCONF_SERVICE_NAME_PREFIX\@,$(XFCONF_SERVICE_NAME_PREFIX),g" \
#	       -e "s,\@XFCONF_SERVICE_PATH_PREFIX\@,$(XFCONF_SERVICE_PATH_PREFIX),g" < $< > $@
#
#xfconf-marshal.h: $(srcdir)/xfconf-marshal.list Makefile
#	$(AM_V_GEN) glib-genmarshal --prefix=_xfconf_marshal $(srcdir)/xfconf-marshal.list --header > xfconf-marshal.h
#xfconf-marshal.c: $(srcdir)/xfconf-marshal.list Makefile
#	$(AM_V_GEN) echo '#include "xfconf-marshal.h"' > xfconf-marshal.c \
#	&& glib-genmarshal --prefix=_xfconf_marshal $(srcdir)/xfconf-marshal.list --body >> xfconf-marshal.c
#
#xfconf-gdbus-bindings.h:
#xfconf-gdbus-bindings.c: xfconf-dbus.xml Makefile
#	$(AM_V_GEN) $(GDBUS_CODEGEN) \
#	--interface-prefix @XFCONF_SERVICE_NAME_PREFIX@.Xfconf \
#	--annotate "@XFCONF_SERVICE_NAME_PREFIX@.Xfconf" "org.gtk.GDBus.C.Name" Exported \
#	--c-namespace Xfconf   \
#	--generate-c-code xfconf-gdbus-bindings \
#	$<
#
#CLEANFILES = \
#	actual-abi \
#	expected-abi
#
#DISTCLEANFILES = \
#	$(libxfconf_built_sources) \
#	$(BUILT_SOURCES) \
#	xfconf-dbus.xml
#
#BUILT_SOURCES += \
#	$(libxfconf_built_sources)
#
#xfconf-alias.h: make-exo-alias.pl $(top_srcdir)/xfconf/xfconf.symbols
#	$(AM_V_GEN) $(PERL) $(srcdir)/make-exo-alias.pl <$(top_srcdir)/xfconf/xfconf.symbols >xfconf-alias.h
#
#xfconf-aliasdef.c: make-exo-alias.pl $(top_srcdir)/xfconf/xfconf.symbols
#	$(AM_V_GEN) $(PERL) $(srcdir)/make-exo-alias.pl -def <$(top_srcdir)/xfconf/xfconf.symbols >xfconf-aliasdef.c
#
#
#EXTRA_DIST = \
#	make-exo-alias.pl \
#	xfconf-alias.h \
#	xfconf-aliasdef.c \
#	xfconf-common-private.h \
#	xfconf-dbus.xml.in \
#	xfconf-marshal.list \
#	xfconf-types.c
#
## required for make distcheck
#dist-hook: all
